<?php

class FS {
	public static function getSubfolders ($folder) {
		$sub = array ();
		
		if (!$handle = opendir ($folder)) {
			return $sub;
		}
		
		while ( ($entry = readdir ($handle)) !== false) {
			if ($entry != '..' && !preg_match ("/^\..{1,}$/i", $entry) && is_dir ($folder . '/' . $entry)) {
				$sub[] = $entry;
			}
		}
		return $sub;
	}
	
	public static function getFiles ($folder, $allowedTypes) {
		$sub = array ();
		
		if (!$handle = opendir ($folder)) {
			return $sub;
		}
		
		$typesStr = join ($allowedTypes, '|');
		
		while ( ($entry = readdir ($handle)) !== false) {
			if (!preg_match ("/^\..{1,}$/i", $entry) && is_file ($folder . '/' . $entry) && preg_match ("/.{1,}\.({$typesStr})/i", $entry)) {
				$sub[] = $entry;
			}
		}
		return $sub;
	}
}

?>